//
//  PwErrorView.m
//  BalanceCar
//
//  Created by 郑信鸿 on 17/6/28.
//  Copyright © 2017年 郑信鸿. All rights reserved.
//

#import "PwErrorView.h"
#import "SeparateLineView.h"

@implementation PwErrorView


- (instancetype)init{
    
    if (self = [super init]) {
        
        [self establishSubViews];
    }
    
    return self;
}


- (void)establishSubViews{
    
    UILabel *label = [[UILabel alloc] init];
    label.text = @"开锁密码错误，请重试";
    label.font = [UIFont systemFontOfSize:17];
    label.textColor = [UIColor colorFromHexCode:@"#666666"];
    label.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label];
    SeparateLineView *lineView = [[SeparateLineView alloc]init];
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.mas_offset(-50);
        make.left.right.mas_offset(0);
        make.height.mas_offset(0.5);
    }];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.right.top.mas_offset(0);
        make.bottom.mas_equalTo(lineView.mas_top).offset(0);
        
    }];
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button1 setTitle:@"重试" forState:UIControlStateNormal];
    button1.tag = 100;
    [self addSubview:button1];
    [button1 setTitleColor:[UIColor colorFromHexCode:@"#333333"] forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    button2.tag = 101;
    [button2 setTitle:@"联系客服" forState:UIControlStateNormal];
    [self addSubview:button2];
    [button2 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [button2 setTitleColor:[UIColor colorFromHexCode:@"#17c549"] forState:UIControlStateNormal];
    NSArray *buttons = @[button1, button2];
    [buttons mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(0);
        make.top.mas_equalTo(lineView.mas_bottom).offset(0);
    }];
    [buttons mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:40 leadSpacing:20 tailSpacing:20];
    
}


- (void)buttonAction:(UIButton *)button{
    
    if ([_delegate respondsToSelector:@selector(pwErrorView:touchWithBtnType:)]) {
        
        [_delegate pwErrorView:self touchWithBtnType:button.tag];
    }
}

@end
